<?php

/**
 * This is the model class for table "{{content}}".
 *
 * The followings are the available columns in table '{{content}}':
 * @property integer $content_id
 * @property string $content_name
 * @property string $content_text
 * @property string $content_alias
 * @property string $content_metatitle
 * @property string $content_metakey
 * @property string $content_metadesc
 */
class Content extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Content the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{content}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('content_name, content_text, content_alias', 'required'),
			array('content_name, content_metatitle, content_metakey, content_metadesc', 'length', 'max'=>1000),
			array('content_alias', 'length', 'max'=>255),
			array('content_alias', 'match', 'pattern'=>'/^[a-z0-9_-]+$/', 'message'=>'Псевдоним должен состоять из "a-z", "0-9", "_", "-"'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('content_id, content_name, content_text, content_alias, content_metatitle, content_metakey, content_metadesc', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'content_id' => 'Страницы',
			'content_name' => 'Названия',
			'content_text' => 'Текст',
			'content_alias' => 'Псевдоним',
			'content_metatitle' => 'Meta Title',
			'content_metakey' => 'Meta Key',
			'content_metadesc' => 'Meta Desc',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('content_id',$this->content_id);
		$criteria->compare('content_name',$this->content_name,true);
		$criteria->compare('content_text',$this->content_text,true);
		$criteria->compare('content_alias',$this->content_alias,true);
		$criteria->compare('content_metatitle',$this->content_metatitle,true);
		$criteria->compare('content_metakey',$this->content_metakey,true);
		$criteria->compare('content_metadesc',$this->content_metadesc,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}